<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Mail;
use Log;

class SendReminderEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $email;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($emai)
    {
        $this->email = $emai;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(): void
    {
        $tomail = $this->email;
        if ($tomail !== null && $tomail !== '') {
            Log::debug("test1".$tomail);
            $subject = '【メールテスト】';
            Mail::raw("emails.newEmails", function ($message) use ($tomail, $subject) {
                $message->from(config('mail.from')['address'], mb_encode_mimeheader(config('mail.from')['name']))
                    ->to($tomail)
                    ->subject($subject);
            });
            if (count(Mail::failures()) >= 1) {
                Log::debug("test1error".now());
            }
        }
    }
}
